<template>
  <el-dialog title="部门编辑" :visible.sync="visible" append-to-body fullscreen center>
    <el-button class="miui-dialog-close-btn" @click="visible = false">关闭页面</el-button>
    <el-form class="verify-form" size="medium" :model="dataForm" :rules="dataRule" ref="dataForm" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="部门编码" prop="deptCode">
            <el-input v-model="dataForm.deptCode" placeholder="部门编码" readonly>
              <el-button slot="append" :disabled="!!dataForm.id" @click="deptClickHandle">选择</el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="部门名称" prop="deptName">
            <el-input v-model="dataForm.deptName" placeholder="部门id" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="部门电话" prop="iphone">
            <el-input v-model="dataForm.iphone" placeholder="部门电话"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="部门地址" prop="address">
            <el-input v-model="dataForm.address" placeholder="部门地址"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="地址坐标X轴" prop="latitude">
            <el-input v-model="dataForm.latitude" placeholder="地址坐标X轴(纬度)">
              <template slot="append">维度</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="地址坐标Y轴" prop="longitude">
            <el-input v-model="dataForm.longitude" placeholder="地址坐标Y轴(经度)">
              <template slot="append">经度</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="微信标题图" prop="wechatTitlePicture">
            <el-upload
              ref="upload"
              action="/pvm/wxImage/uploadFileByOptometry"
              list-type="picture-card"
              :data="{deptId: this.dataForm.deptId}"
              :auto-upload="false">
                <i slot="default" class="el-icon-plus"></i>
                <div slot="file" slot-scope="{file}">
                  <img
                    class="el-upload-list__item-thumbnail"
                    :src="file.url" alt=""
                  >
                  <span class="el-upload-list__item-actions">
                    <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
                      <i class="el-icon-zoom-in"></i>
                    </span>
                    <span class="el-upload-list__item-delete" @click="handleRemove(file)">
                      <i class="el-icon-delete"></i>
                    </span>
                  </span>
                </div>
            </el-upload>
            <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="12">

        </el-col>
        <el-col :span="24">
          <el-form-item label="微信可见" prop="showFlag">
            <el-radio-group v-model="dataForm.showFlag">
              <el-radio label="1">可见</el-radio>
              <el-radio label="0">不可见</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="medium" @click="visible = false">取消</el-button>
      <el-button size="medium" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    <search-dept v-if="deptVisible" ref="deptDialog" @refreshData="getDeptData"></search-dept>
  </el-dialog>
</template>

<script>
  import SearchDept from './SearchDept'

  export default {
    data() {
      return {
        visible: false,
        deptVisible: false,
        dataForm: {
          deptCode: '',
          deptName: '',
          iphone: '',
          address: '',
          latitude: '',
          longitude: '',
          showFlag: ''
        },
        fileList: []
      }
    },
    components: {
      SearchDept
    },
    methods: {
      init(){
        this.visible = true
      },
      // 打开部门选择框
      deptClickHandle(){
        this.deptVisible = true
        this.$nextTick(() => {
          this.$refs.deptDialog.init(this.dataForm.deptId)
        })
      },
      // 获取部门数据
      getDeptData(data){

      },
      // 图片上传事件
      submitUpload(){
        this.$refs.upload.submit()
      },

      handlePictureCardPreview(file) {
              this.dialogImageUrl = file.url;
              this.dialogVisible = true;
            },
      handleRemove(file) {
              console.log(file);
            },
      // 图片上传之前
      beforeUpload(file){

      },
      // 图片上传成功
      uploadSuccess(){

      },
      // 提交保存
      dataFormSubmit(){

      }
    }
  }
</script>

<style lang="scss" scoped>
  .search-area {
    background-color: #d8e6db;
    display: flex;
    justify-content: space-between;
    padding: 10px;
    margin-bottom: 10px;
  }
  .content-list {
    height: calc(100vh - 200px);
    overflow-y: auto;
    margin-bottom: 10px;
  }
  .paging-area {
    background-color: #d8e6db;
    padding: 10px;
  }
</style>
